package com.voice.core.utils;

import java.nio.ByteBuffer;
import java.util.Arrays;

public class BytesUtil {

    public static int getInt(byte[] bytes,int position){
        ByteBuffer buffer=ByteBuffer.wrap(bytes,position,4);
        return buffer.getInt();
    }

    public static long getLong(byte[] bytes,int position){
        ByteBuffer buffer=ByteBuffer.wrap(bytes,position,8);
        return buffer.getLong();
    }

    public static byte[] intToBytes(int num,int size){
        byte[] bytes=new byte[size];
        for(int i=0;i<size;i++){
            bytes[i]=(byte)(num>>(size-i-1)*8&0xff);
        }
        return bytes;
    }

}
